package com.polytech.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.polytech.beans.Color;
public class HibernateSessionFactory {
	private static SessionFactory sessionFactory=null;
	
	static
	{
		try {
			System.out.println(">>> HibernateSessionFactory STATIC BLOCK");
			Configuration conf = new Configuration().configure();
			sessionFactory=conf.buildSessionFactory();
			System.out.println(">>> Fin de configuaration");
			
	
		} catch (Exception e) {
			System.err.println("Initial SessionFactory creation failed." + e);
		}
	}
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public static org.hibernate.Session openSession() {
		return sessionFactory.openSession();
	}
//	public static void main(String[] args) {
//		Session session = openSession();
//		Transaction tran = session.beginTransaction();
//		 Color color=new Color("Bleu",1);
//		 session.save(color);
//		tran.commit();
//	}
}
